<template>
  <div>
    <el-row
      :span="24"
      class="body"
      style="margin-left: 0; margin-right: 0" :gutter="20" >

      <el-col
        :span="12"
        class="content"
        style="position: relative; padding: 0 !important" >
        <div id="charts1"   class="line"
             :style="{ width: '100%', margin: '0 auto' }"
             ref="charts1"></div>
      </el-col>

      <el-col
        :span="12"
        class="content"
        style="position: relative; padding: 0 !important" >
        <div id="charts2"   class="line"
             :style="{ width: '100%', margin: '0 auto' }"
             ref="charts2"></div>
      </el-col>

      <el-col
        :span="24"
        class="content"
        style="position: relative; padding: 0 !important" >
        <div id="charts3"   class="line"
             :style="{ width: '100%', margin: '0 auto' }"
             ref="charts3"></div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import * as echarts from "echarts";
export default{
  mounted() {
    this.drawChart1();
    this.drawChart2();
    this.drawBarChart();
  },
  methods:{
    //图表1
    drawChart1() {
      var chartDom = document.getElementById('charts1');
      var myChart = echarts.init(chartDom);
      var option;
      option = {
        title: {
          text: '老人请假统计',
          // subtext: 'Fake Data',
          left: 'center'
        },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          orient: 'vertical',
          left: 'left'
        },
        series: [
          {
            name: '请假类型',
            type: 'pie',
            radius: '50%',
            data: [
              { value: 5, name: '探亲' },
              { value: 7, name: '看病' },
              { value: 1, name: '体检' },
              { value: 1, name: '其他' }
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      };
      option && myChart.setOption(option);
    },
    drawChart2() {
      var chartDom = document.getElementById('charts2');
      var myChart = echarts.init(chartDom);
      var option;
      option = {
        title: {
          text: '老人请假返回状态统计',
          // subtext: 'Fake Data',
          left: 'center'
        },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          top: '5%',
          left: 'center'
        },
        series: [
          {
            name: '返回情况',
            type: 'pie',
            radius: ['40%', '70%'],
            avoidLabelOverlap: false,
            label: {
              show: false,
              position: 'center'
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 40,
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            data: [
              { value: 48, name: '未返回' },
              { value: 200, name: '返回' },
              { value: 82, name: '不健康' }
            ]
          }
        ]
      };
      option && myChart.setOption(option);
    },
    //图表3
    drawBarChart() {
      var chartDom = document.getElementById('charts3');
      var myChart = echarts.init(chartDom);
      var option;
      option = {
        title: {
          text: '老人情况情况统计',
          // subtext: 'Fake Data',
          left: 'center'
        },
        tooltip: {
          trigger: 'item'
        },
        xAxis: {
          type: 'category',
          data: ['2023-02-11', '2023-02-12', '2023-02-13', '2023-02-14', '2023-02-15', '2023-02-16', '2023-02-17']
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: [1, 0, 5, 1, 7, 3, 1],
            type: 'bar',
            showBackground: true,
            backgroundStyle: {
              color: 'rgba(180, 180, 180, 0.2)'
            }
          }
        ]
      };
      option && myChart.setOption(option);
    },
  }
}
</script>

<style scoped>
.line{
  height: 450px;
  padding: 10px;
}
</style>
